$(document).ready(function() {


    zoom_photo();
//paging
    var killScroll = false;
    $(window).scroll(function() {
        if ($('#loadmore_product').val() == 1) {
            if ($(window).scrollTop() > ($(document).height() - $(window).height() - 100)) {
                $("#loading").show();
                if (killScroll === false) {
                    killScroll = true;
                    var category_id= $(".mrk_select_crawl_category").val();
                    $.post("ajax/loadMoreCrawlProduct.php", {
                        page: $('#page_product').val(),
                        category_id: category_id
                    }, function(res) {
                        $("#loading").hide();
                        $("#tbody_product_list").append(res.html);
                        $('#page_product').val(res.page);
                        $('#loadmore_product').val(res.load_more);

                        zoom_photo();
                        killScroll = false;
                        $("#loading").hide();
                    }, "json");
                } else {
                    return false;
                }
            }
        }
    });

    $(".mrk_select_crawl_category").on('change',function(){
        $.post("ajax/loadMoreCrawlProduct.php", {
            page: 0,
            category_id: $(this).val()
        }, function(res) {

            $("#tbody_product_list").html(res.html);
            $('#page_product').val(res.page);
            $('#loadmore_product').val(res.load_more);
            $("#total_product").html(res.total);
            zoom_photo();

        }, "json");
    });
});

function zoom_photo() {
    $(".photo_product").click(function() {
        $("#photo_zoom").html('<img width="500px" src="' + $(this).attr('rel') + '">');
        $('#modal_photo_zoom').modal('show');
    });
}


